<?php
/**
 * Created by PhpStorm.
 * User: jacob
 * Date: 18-8-8
 * Time: 下午5:48
 */

class ProjectInit{
  private static $sub_dirs = [
    'config',
    'tiny',
    'db'
  ];
  private static $file_exts = [
    'inc'
  ];
  public static $objects = [

  ];

  public static function init(){
    self::autoRegister();
  }

  public static function autoRegister(){
    foreach (self::$sub_dirs as $sub_dir){
      $path = dirname(__FILE__)."/".$sub_dir;
      self::getfiles($path);
    }
  }

  public static function addObject($obj){
    self::$objects[] = $obj;
  }

  private static function getfiles(string $path){
    if (is_dir($path)){
      $dir = dir($path);
      while ($file = $dir->read()){
        if ($file != "." && $file != ".."){
          self::getfiles($path.'/'.$file);
        }
      }
      $dir->close();
    }else{
      $ext = explode(".",$path);
      if (in_array(end($ext),self::$file_exts)) self::addObject($path);
    }
  }

}